import 'package:flutter/material.dart';
import 'package:flutter_base/inheritedwidget_demo/components/sharedata_widget.dart';

class OtherTestWidget extends StatefulWidget {
  const OtherTestWidget({super.key});

  @override
  State<OtherTestWidget> createState() => _OtherTestWidgetState();
}

class _OtherTestWidgetState extends State<OtherTestWidget> {
  @override
  Widget build(BuildContext context) {
    // 使用InheritedWidget中的数据
    return Text(ShareDataWidget.of(context)!.data.toString());
  }

  @override
  void didChangeDependencies() {
    // 父或祖Widget中InheritedWidget改变（updateShouldNotify返回true）时会被调用，
    // 如果build中没有依赖InheWidget，则此回调不会调用
    debugPrint('change Dependencies');
    super.didChangeDependencies();
  }
}
